package com.ruoyi.comment.controller;

import com.ruoyi.comment.domain.EvaluationResult;
import com.ruoyi.comment.service.IEvaluationResultService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 测评结果Controller
 * 
 * @author ruoyi
 * @date 2025-08-12
 */
@RestController
@RequestMapping("/comment/result")
public class EvaluationResultController extends BaseController
{
    @Autowired
    private IEvaluationResultService evaluationResultService;

    /**
     * 查询测评结果列表
     */
    @PreAuthorize("@ss.hasPermi('comment:result:list')")
    @GetMapping("/list")
    public TableDataInfo list(EvaluationResult evaluationResult)
    {
        startPage();
        List<EvaluationResult> list = evaluationResultService.selectEvaluationResultList(evaluationResult);
        return getDataTable(list);
    }

    /**
     * 导出测评结果列表
     */
    @PreAuthorize("@ss.hasPermi('comment:result:export')")
    @Log(title = "测评结果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EvaluationResult evaluationResult)
    {
        List<EvaluationResult> list = evaluationResultService.selectEvaluationResultList(evaluationResult);
        ExcelUtil<EvaluationResult> util = new ExcelUtil<EvaluationResult>(EvaluationResult.class);
        util.exportExcel(response, list, "测评结果数据");
    }

    /**
     * 获取测评结果详细信息
     */
    @PreAuthorize("@ss.hasPermi('comment:result:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(evaluationResultService.selectEvaluationResultById(id));
    }

    /**
     * 新增测评结果
     */
    @PreAuthorize("@ss.hasPermi('comment:result:add')")
    @Log(title = "测评结果", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EvaluationResult evaluationResult)
    {
        return toAjax(evaluationResultService.insertEvaluationResult(evaluationResult));
    }

    /**
     * 修改测评结果
     */
    @PreAuthorize("@ss.hasPermi('comment:result:edit')")
    @Log(title = "测评结果", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EvaluationResult evaluationResult)
    {
        return toAjax(evaluationResultService.updateEvaluationResult(evaluationResult));
    }

    /**
     * 删除测评结果
     */
    @PreAuthorize("@ss.hasPermi('comment:result:remove')")
    @Log(title = "测评结果", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(evaluationResultService.deleteEvaluationResultByIds(ids));
    }
}
